<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
 */
class UserFactory extends Factory
{
    /**
     * The current password being used by the factory.
     */
    protected static ?string $password;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'openid' => 'wx_openid_' . Str::random(32),
            'unionid' => 'wx_unionid_' . Str::random(32),
            'nickname' => fake()->name(),
            'avatar' => fake()->imageUrl(200, 200, 'people'),
            'phone' => fake()->phoneNumber(),
            'gender' => fake()->numberBetween(0, 2),
            'city' => fake()->city(),
            'province' => fake()->state(),
            'country' => '中国',
            'language' => 'zh_CN',
            'last_login_at' => now(),
            'is_active' => true,
        ];
    }

    /**
     * 创建测试用户（简化版本）
     */
    public function testUser(): static
    {
        return $this->state(fn (array $attributes) => [
            'openid' => 'test_openid_' . Str::random(16),
            'unionid' => 'test_unionid_' . Str::random(16),
            'nickname' => '测试用户',
            'avatar' => 'https://example.com/avatar.jpg',
            'phone' => '13800138000',
            'gender' => 1,
            'city' => '北京',
            'province' => '北京',
            'country' => '中国',
            'language' => 'zh_CN',
            'is_active' => true,
        ]);
    }

    /**
     * Indicate that the model's email address should be unverified.
     */
    public function unverified(): static
    {
        return $this->state(fn (array $attributes) => [
            'email_verified_at' => null,
        ]);
    }
}
